<?php
// @formatter:off
/**
 * @file c.version.php
 * @author Alejandro Dario Simi
 * @date $Date: 2013-06-16 23:56:49 +0000 (Sun, 16 Jun 2013) $
 *
 * $Id: c.version.php 73 2013-06-16 23:56:49Z daemonraco@gmail.com $
 * $URL: http://wcomix.googlecode.com/svn/tags/wcomix-1.0-BETA1/themes/default/controlers/contents/c.version.php $
 */
// @formatter:on

if($wcProfile->allowedTo(WC_PERM_SPECIAL_VERSION)) {
	global $wcRuleHooks;
	global $wcRightAdds;
	global $wcCanvasActions;
	global $wcRightTools;
	global $wcExtensionInfo;

	$wcThemeAssigns["PATH"] = "Version";
	$wcThemeAssigns["ACTIONCONTENT"] = "/contents/c.version.html";
	$wcThemeAssigns["ACTIONEXTERNALSTYLE"] = "{$this->_themeUri}/templates/contents/c.version.css";

	$extensions = array();
	$rules = array();
	$canvas = array();

	foreach($wcRuleHooks as $type => $hook) {
		$aux = array(
			"type" => "Rule Hook",
			"name" => $hook["name"],
			"description" => $hook["description"],
			"version" => $hook["version"],
			"url" => $hook["url"],
			"copyright" => $hook["author"],
			"marker" => "RULES",
			"lock-tags" => isset($hook["lock-tags"]) ? "Y" : "N"
		);
		if(is_array($hook["url"])) {
			$aux["url"] = $hook["url"]["href"];
			$aux["url-title"] = $hook["url"]["title"];
		} else {
			$aux["url"] = $hook["url"];
		}
		$rules[] = $aux;
		$extensions[$aux["name"]] = $aux;
	}

	foreach($wcRightAdds as $id => $ad) {
		if(isset($ad["name"])) {
			$aux = array(
				"type" => "Ads",
				"name" => $ad["name"],
				"description" => $ad["description"],
				"version" => $ad["version"],
				"url" => $ad["url"],
				"copyright" => $ad["author"],
				"marker" => "ADDS"
			);
			if(is_array($ad["url"])) {
				$aux["url"] = $ad["url"]["href"];
				$aux["url-title"] = $ad["url"]["title"];
			} else {
				$aux["url"] = $ad["url"];
			}
			$extensions[$aux["name"]] = $aux;
		}
	}
	foreach($wcRightTools as $id => $tool) {
		if(isset($tool["name"])) {
			$aux = array(
				"type" => "Right Tool",
				"name" => $tool["name"],
				"description" => $tool["description"],
				"version" => $tool["version"],
				"url" => $tool["url"],
				"copyright" => $tool["author"],
				"marker" => "RTOOLS"
			);
			if(is_array($tool["url"])) {
				$aux["url"] = $tool["url"]["href"];
				$aux["url-title"] = $tool["url"]["title"];
			} else {
				$aux["url"] = $tool["url"];
			}
			$extensions[$aux["name"]] = $aux;
		}
	}

	foreach($wcCanvasActions as $id => $action) {
		if(isset($action["name"])) {
			$aux = array(
				"type" => "Canvas Action",
				"name" => $action["name"],
				"saction" => $id,
				"description" => $action["description"],
				"version" => $action["version"],
				"url" => $action["url"],
				"copyright" => $action["author"],
				"marker" => "CANVAS",
				"pre-js" => isset($action["pre-js"]) ? "Y" : "N",
				"post-js" => isset($action["post-js"]) ? "Y" : "N"
			);
			if(is_array($action["url"])) {
				$aux["url"] = $action["url"]["href"];
				$aux["url-title"] = $action["url"]["title"];
			} else {
				$aux["url"] = $action["url"];
			}
			if(isset($action["name-url"]) && $action["name-url"]) {
				$aux["url-name"] = "?action=".WC_ACTION_CANVAS."&group={$wcGroup->id()}&saction={$id}";
			}
			$canvas[$aux["name"]] = $aux;
			$extensions[$aux["name"]] = $aux;
		}
	}

	foreach($wcExtensionInfo as $id => $extension) {
		if(isset($extension["name"])) {
			$aux = array();

			$name = $extension["name"];
			$aux["type"] = "Extension";

			if(isset($extensions[$name])) {
				$aux["type"] = $extensions[$name]["type"];

				if(isset($extensions[$name]["url-name"])) {
					$aux["url-name"] = $extensions[$name]["url-name"];
				}
			}

			$aux["name"] = $name;
			$aux["description"] = $extension["description"];
			$aux["version"] = $extension["version"];
			$aux["url"] = $extension["url"];
			$aux["copyright"] = $extension["author"];

			if(is_array($extension["url"])) {
				$aux["url"] = $extension["url"]["href"];
				$aux["url-title"] = $extension["url"]["title"];
			} else {
				$aux["url"] = $extension["url"];
			}

			$extensions[$name] = $aux;
		}
	}

	ksort($extensions);
	ksort($canvas);

	$wcThemeAssigns["extensions"] = $extensions;
	$wcThemeAssigns["rules"] = $rules;
	$wcThemeAssigns["canvas"] = $canvas;
} else {
	$wcThemeAssigns["error-string"] = "You're not allowed to visit the version page";
	require "{$this->_themeRoot}/controlers/contents/c.403.php";
}
?>